package oen.game.unpack.tools.handler.netease;

import im.oen.boot.common.utils.ByteUtil;
import im.oen.boot.common.utils.Checker;
import oen.game.unpack.tools.handler.FileHandler;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Set;
import java.util.logging.Level;

/**
 * <p>描述：暂无描述信息</p>
 *
 * <p>创建时间：2021-11-10 18:05</p>
 * <p>更新时间：暂无</p>
 *
 * @author Kevin.Xu
 * @version 1.0
 */
public class NpkFileHandler extends FileHandler {

    @Override
    public boolean isSupport(File file) {
        if (file == null || !file.exists()) {
            return false;
        }
        return file.getName().endsWith(".npk");
    }

    @Override
    public void process(Set<File> files) throws Exception {
        if (Checker.isEmpty(files)) {
            return;
        }

        for (File file : files) {
            this.process(file);
        }
    }

    private void process(File file) throws IOException {
        log.log(Level.INFO, "Start process file : {}", file.getName());
        byte[] bytes = Files.readAllBytes(file.toPath());
        byte[] size = ByteUtil.fetch(bytes, 4, 4);
    }

    private int byteToInt(byte[] bytes) {
        Integer a = Integer.valueOf((char) bytes[0] & 0xFF);
        Integer b = Integer.valueOf((char) bytes[1] & 0xFF);
        Integer c = Integer.valueOf((char) bytes[2] & 0xFF);
        Integer d = Integer.valueOf((char) bytes[3] & 0xFF);
        return (a | b << 8 | c << 16 | d << 24);
    }
}
